package sample.util.alert;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;

/**
 * Created by 杨家兵 on 2016/11/5.
 */
public class AlertBox {
    public static void display(String title , String message){
        final Stage window = new Stage();
        window.setTitle(title);
        //modality要使用Modality.APPLICATION_MODEL
        window.initModality(Modality.APPLICATION_MODAL);

        Button button = new Button("Close the window");
        button.setOnAction(new EventHandler<ActionEvent>(){
            public void handle(ActionEvent e){
                window.close();
            }
        });

        Label label = new Label(message);

        VBox layout = new VBox(50);
        layout.getChildren().addAll(label , button);
        layout.setAlignment(Pos.CENTER);

        Scene scene = new Scene(layout,300,150);
        scene.getStylesheets().add("/css/DarkTheme.css");
        window.setScene(scene);
        window.setResizable(false);
        //使用showAndWait()先处理这个窗口，而如果不处理，main中的那个窗口不能响应
        window.showAndWait();
    }
}
